File manager - Edit - /home/autoph/public_html/projects/event-registration-api/app/Models/EventParticipant.php
Back
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class EventParticipant extends Model { use HasFactory; protected $table = "golf_players"; public $timestamps = false; /** * The attributes that are mass assignable. * * @var array<int, string> */ protected $guarded = [ ]; /** * The attributes that should be cast. * * @var array<string, string> */ protected $casts = [ ]; protected $appends = ['attendance','sms_status', 'sms_details']; protected $with = ['participant']; public function participant() { return $this->hasOne( User::class, 'id', 'user_id' ); } public function event() { return $this->hasOne( Event::class, 'id', 'event_id' ); } public function booth_visit() { return $this->belongsToMany( Booth::class, BoothVisit::class, 'player_id', 'booth_id', )->withPivot(['event_id','created_at']); } public function getAttendanceAttribute() { $attendance = Attendance::select('created_at')->where('player_id', $this->id)->where('status', 1)->first(); return $attendance->created_at ?? null; } public function getSmsDetailsAttribute() { $sms = SmsSend::select('golf_sms_report.response', 'golf_sms_report.created_at') ->join('golf_sms_report', 'golf_sms_send.id', '=', 'golf_sms_report.send_sms_id') ->join('golf_users', 'golf_sms_report.target_id', '=', 'golf_users.id') ->where('golf_sms_send.data', 'like', '%"event_id":"'.$this->event_id.'"%') ->where("golf_users.id", '=', $this->user_id) ->orderByDesc('golf_sms_report.id')->get(); // return count($sms); if(count($sms)>0) { $sms = $sms->toArray(); // return $sms; $success = in_array('1',array_column($sms,'response')); $result = [ 'status'=>$success, 'attempts'=>count($sms), 'date_last_sent' => $sms[0]['created_at'], 'error_message' =>$sms[0]['response'] != '1' ? json_decode($sms[0]['response'], true) : null ]; return $result; } return ['status'=>false, 'attempts'=>0, 'error_message'=>null, 'date_last_attempt'=>null]; } public function getSmsStatusAttribute() { $sms = SmsSend::select('golf_sms_report.response', 'golf_sms_report.created_at') ->join('golf_sms_report', 'golf_sms_send.id', '=', 'golf_sms_report.send_sms_id') ->join('golf_users', 'golf_sms_report.target_id', '=', 'golf_users.id') ->where('golf_sms_send.data', 'like', '%"event_id":"'.$this->event_id.'"%') ->where("golf_users.id", '=', $this->user_id) ->orderByDesc('golf_sms_report.id')->get(); // dd(\DB::getQueryLog()); // return count($sms); if(count($sms)>0) { $sms = $sms->toArray(); // return $sms; $success = in_array('1',array_column($sms,'response')); return $success ? 'sent' : 'failed'; } else { return 'unsend'; } } }
| ver. 1.4 |
.
| PHP 8.1.32 | Generation time: 0 |
proxy
|
phpinfo
|
Settings